#include "ParserTest.h"

ParserTest::ParserTest()
{
}

ParserTest::~ParserTest()
{
}

void testRegExps(Regexp* expected, string regexpAsString) {
	Parser parser;
	string expression = parser.expandRegexp(regexpAsString);
	cout << "test " << regexpAsString << " : == " << expression << " --- " << parser.toPostFix(expression) << endl;
	Regexp* regExp = parser.toRegexp(regexpAsString);
	set<string> language = expected->getLanguage(6);
	set<string> language2 = regExp->getLanguage(6);
	cout << "expected = " << language << endl;
	cout << "regexp = " << language2 << endl;
	//assert((language) == (language2));
	delete regExp;
}

void ParserTest::testProgram()
{
	cout<<"Parser Test"<<endl << "==================================="<<endl<<endl;

	//string regexp = "baba";
	//Regexp* expected = new Regexp(regexp);
	//assertRegExps(expected, regexp);

	string regexp = "b(a|b)";
	Regexp* expected = new Regexp(regexp);
	expected = (new Regexp("b"))->dot((new Regexp("a"))->or(new Regexp("b")));
	testRegExps(expected, regexp);
	cout<< "------------------------------------------------------------------------------" << endl<<endl;

	expected = (new Regexp("a"))->star();
	testRegExps(expected, "a*");
	cout<< "------------------------------------------------------------------------------" << endl<<endl;


	expected = (new Regexp("b"))->plus();
	testRegExps(expected, "b+");
	cout<< "------------------------------------------------------------------------------" << endl<<endl;


	Regexp* a = new Regexp("a");
	Regexp* b = new Regexp("b");

	Regexp* astardotb = a->star()->dot(b->plus());
	testRegExps(astardotb, "a*b+");
	cout<< "------------------------------------------------------------------------------" << endl<<endl;


	cout << endl<<endl;
}
